﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Admx_Generator
{
    internal partial class FrmEditPrefix : Form
    {
        internal FrmEditPrefix(string currentPrefix)
        {
            InitializeComponent();

            this.txtBxCurrentPrefix.Text = currentPrefix;
            List<char> allowedChars = Utilities.GetAllowedCharacters();
            try
            {
                this.fltTxtBxNewPrefix.AllowedCharacters.AddRange(allowedChars);
                this.fltTxtBxNewPrefix.AllowedCharacters.Add('_');
            }
            catch (Exception) { }
        }

        #region (Properties)

        /// <summary>
        /// Gets or Sets the new prefix
        /// </summary>
        internal string NewPrefix { get; private set; }
        
        #endregion (Properties)

        #region (Methods)

        /// <summary>
        /// Check user entries and allow or disallow the 'Ok' button accordingly
        /// </summary>
        private void ValidateData()
        {
            this.btnOk.Enabled = !String.IsNullOrEmpty(this.fltTxtBxNewPrefix.Text);
        }
        
        #endregion (Methods)

        #region (UI Managment)

        private void fltTxtBxNewPrefix_TextChanged(object sender, EventArgs e)
        {
            this.ValidateData();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            this.NewPrefix = this.fltTxtBxNewPrefix.Text;
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        #endregion (UI Managment)
    }
}
